<template>
  <div>
    <!-- This section should be hidden by default and shown when there are todos -->
    <section class="main">
      <input id="toggle-all" class="toggle-all" type="checkbox" />
      <label for="toggle-all">全部标记为已完成</label>
      <ul class="todo-list">
        <!-- These are here just to show the structure of the list items -->
        <!-- List items should get the class `editing` when editing and `completed` when marked as completed -->

        <!-- isdone=true的任务表示已完成,已完成的数据,加入completed 类名 -->
        <li
          :class="{ completed: item.isDone }"
          v-for="item in list"
          :key="item.id"
        >
          <div class="view">
            <!-- isdone=true的任务表示已完成,则勾选 -->
            <input
              class="toggle"
              type="checkbox"
              :checked="item.isDone"
              @change="$emit('state', item.id)"
            />
            <label>{{ item.name }}</label>
            <!-- 删除 -->
            <!-- 子组件删除 -->
            <button class="destroy" @click="$emit('del', item.id)"></button>
          </div>
          <input class="edit" value="Create a TodoMVC template" />
        </li>
        <!-- <li>
          <div class="view">
            <input class="toggle" type="checkbox" />
            <label>中午吃大饼卷大葱</label>
            <button class="destroy"></button>
          </div>
          <input class="edit" value="Rule the web" />
        </li> -->
      </ul>
    </section>
  </div>
</template>

<script>
export default {
  props: {
    list: Array,
  },
  //计算属性 做全选
  computed:{
    //对象写法
    all:{
      get(){
        return this.list.every(item => item.isDone === true)
      },
      set(val){
        this.$emit('changeAll',val)
      }
    }
  }
};
</script>

<style >
</style>